package com.sgb.kjwl.view.ui.activity.self.pick;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityPeopleDetailedListBinding;
import com.sgb.kjwl.view.ui.fragment.self.pick.ProjectDetailedListFragment;
import com.sgb.kjwl.view.ui.fragment.self.pick.UserLaborFragment;
import com.sgb.kjwl.view.ui.fragment.self.pick.UserMachineFragment;
import com.sgb.kjwl.view.ui.fragment.self.pick.UserMaterialFragment;
import com.sgb.kjwl.viewmodel.self.pick.PeopleDetailedListModel;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;

import java.util.ArrayList;

import javax.inject.Inject;

public class PeopleDetailedListActivity extends AppActivity {
    private ActivityPeopleDetailedListBinding binding;
    @Inject
    PeopleDetailedListModel viewModel;

    private String[] titles = {"分项工程清单", "材料","机械设备","劳务"};
    private SlidingFragmentPagerAdapter pagerAdapter;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private String id;

    public static void start(Context context, String id) {
        Intent intent = new Intent();
        intent.putExtra("id", id);
        intent.setClass(context, PeopleDetailedListActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected boolean statusBarDark() {
        return true;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        id = getIntent().getStringExtra("id");

        binding = DataBindingUtil.setContentView(PeopleDetailedListActivity.this, R.layout.activity_people_detailed_list);
        binding.setViewModel(viewModel);
        binding.include.titleView.setText("人材机清单");
        binding.include.ivBack.setOnClickListener(this);

        mFragments.add(ProjectDetailedListFragment.newInstance(id));
        mFragments.add(UserMaterialFragment.newInstance(id));
        mFragments.add(UserMachineFragment.newInstance(id));
        mFragments.add(UserLaborFragment.newInstance(id));

        pagerAdapter = new SlidingFragmentPagerAdapter(getSupportFragmentManager(), mFragments, titles);
        binding.viewpager.setAdapter(pagerAdapter);
        binding.viewpager.setOffscreenPageLimit(4);
        binding.tabLayout.setupWithViewPager(binding.viewpager);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
